home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
bbsutil
/
bsrc_250.zip
/
XMREC.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-09-15
|
37KB
|
1,249 lines
/*--------------------------------------------------------------------------*/
/* */
/* */
/* ------------ Bit-Bucket Software, Co. */
/* \ 10001101 / Writers and Distributors of */
/* \ 011110 / Freely Available<tm> Software. */
/* \ 1011 / */
/* ------ */
/* */
/* (C) Copyright 1987-91, Bit Bucket Software Co., a Delaware Corporation. */
/* */
/* */
/* This module was written by Bob Hartman */
/* */
/* */
/* BinkleyTerm Xmodem Receiver State Machine */
/* */
/* */
/* For complete details of the licensing restrictions, please refer */
/* to the License agreement, which is published in its entirety in */
/* the MAKEFILE and BT.C, and also contained in the file LICENSE.250. */
/* */
/* USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE */
/* BINKLEYTERM LICENSING AGREEMENT. IF YOU DO NOT FIND THE TEXT OF */
/* THIS AGREEMENT IN ANY OF THE AFOREMENTIONED FILES, OR IF YOU DO */
/* NOT HAVE THESE FILES, YOU SHOULD IMMEDIATELY CONTACT BIT BUCKET */
/* SOFTWARE CO. AT ONE OF THE ADDRESSES LISTED BELOW. IN NO EVENT */
/* SHOULD YOU PROCEED TO USE THIS FILE WITHOUT HAVING ACCEPTED THE */
/* TERMS OF THE BINKLEYTERM LICENSING AGREEMENT, OR SUCH OTHER */
/* AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO. */
/* */
/* */
/* You can contact Bit Bucket Software Co. at any one of the following */
/* addresses: */
/* */
/* Bit Bucket Software Co. FidoNet 1:104/501, 1:343/491 */
/* P.O. Box 460398 AlterNet 7:491/0 */
/* Aurora, CO 80046 BBS-Net 86:2030/1 */
/* Internet f491.n343.z1.fidonet.org */
/* */
/* Please feel free to contact us at any time to share your comments about */
/* our software and/or licensing policies. */
/* */
/*--------------------------------------------------------------------------*/
/* Include this file before any other includes or defines! */
#include "includes.h"
void Find_Char (int);
int Header_in_data (unsigned char *);
void Send_ACK (XMARGSP);
void Send_NAK (XMARGSP);
long Open_Xmodem_File (XMARGSP);
int XRInit (XMARGSP, int);
int XREnd (XMARGSP, int);
int XRRecInit (XMARGSP);
int XRBrecInit (XMARGSP);
int XRRecStart (XMARGSP);
int XRWaitFirst (XMARGSP);
int XRWaitBlock (XMARGSP);
int XRRestart (XMARGSP);
int XRSetOvrdr (XMARGSP);
STATES Xmodem_Receiver[] = {
{ "XRInit", XRInit },
{ "XREnd", XREnd },
{ "XR0", XRRecInit },
{ "XR0B", XRBrecInit },
{ "XR1", XRRecStart },
{ "XR2", XRWaitFirst },
{ "XR3", XRWaitBlock },
{ "XR4", XRRestart },
{ "XR5", XRSetOvrdr }
};
long Open_Xmodem_File (XMARGSP args)
{
char *s1, *s2;
if (args->file_pointer == NULL)
{
args->temp_name = calloc (1, 80);
if (args->path != NULL)
(void) strcpy (args->temp_name, args->path);
s1 = &(args->temp_name[strlen (args->temp_name)]);
(void) strcpy (s1, "BTXXXXXX");
s2 = mktemp (args->temp_name);
if ((s2 == NULL) || ((args->file_pointer = fopen (s2, "wb")) == NULL))
{
status_line (MSG_TXT(M_TEMP_NOT_OPEN), s2);
return (-1L);
}
}
throughput (0, 0L);
return (0L);
}
long Set_Up_Restart (XMARGSP args)
{
char foo[100];
char foo1[50];
struct stat st;
args->sub_results = 0;
/* Look for file in directory */
if (args->path != NULL)
(void) strcpy (foo, args->path);
if ((args->received_name != NULL) &&
(strlen (args->received_name) > 0) &&
args->options.Resync)
{
(void) strcat (foo, args->received_name);
if (stat (foo, &st) == 0)
{
if ((st.st_size == args->filelen) && (st.st_atime == (time_t)(args->save_filetime.oneword.timedate)))
{
if ((args->file_pointer = fopen (foo, "rb+")) != NULL)
{
throughput (0, 0L);
(void) fseek (args->file_pointer, 0L, SEEK_END);
args->sub_results = DID_RESYNC;
args->temp_name = calloc (1, 80);
(void) strcpy (args->temp_name, foo);
args->prev_bytes = args->filelen;
status_line (MSG_TXT(M_ALREADY_HAVE), foo);
status_line (MSG_TXT(M_SYNCHRONIZING_EOF));
return (args->total_blocks + 1L);
}
}
}
/* Look for file in .Z file */
if (dexists (Abortlog_name))
{
(void) sprintf (Resume_info, "%ld %lo", args->filelen, args->save_filetime.oneword.timedate);
if (check_failed (Abortlog_name, args->received_name, Resume_info, foo1))
{
foo[0] = '\0';
/* Here it looks like it was a failed WaZOO session */
if (args->path != NULL)
(void) strcpy (foo, args->path);
(void) strcat (foo, foo1);
if ((args->file_pointer = fopen (foo, "rb+")) != NULL)
{
(void) stat (foo, &st);
throughput (0, 0L);
args->temp_name = calloc(1, 80);
(void) strcpy (args->temp_name, foo);
args->prev_bytes = (st.st_size / 128L) * 128L;
(void) fseek (args->file_pointer, args->prev_bytes, SEEK_SET);
status_line (MSG_TXT(M_SYNCHRONIZING_OFFSET), args->prev_bytes);
return (args->prev_bytes / 128L + 1L);
}
}
}
}
return (Open_Xmodem_File (args));
}
void Finish_Xmodem_Receive (XMARGSP args)
{
struct stat st;
char new_name[80];
struct utimbuf times;
int i, j, k;
/* Set the file's time and date stamp */
if ((args->save_header == SOH) || (args->save_header == SYN))
{
(void) fclose (args->file_pointer);
times.modtime = times.UT_ACTIME = (time_t) args->save_filetime.oneword.timedate;
(void) utime (args->temp_name, (UTIMBUF *)×);
}
else
{
(void) strcpy (args->received_name, "");
(void) fclose (args->file_pointer);
}
if (args->result == SUCCESS)
{
/* Get the file information */
(void) stat (args->temp_name, &st);
throughput (1, (unsigned long) (st.st_size - args->prev_bytes));
update_files (0);
if (args->sub_results & DID_RESYNC)
{
status_line ("%s: %s", MSG_TXT(M_FILE_RECEIVED), args->temp_name);
}